package com.xiaoshuidi.cloud.module.rooms.controller.admin.estimate;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.estimate.vo.*;
import com.xiaoshuidi.cloud.module.rooms.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.rooms.service.IEstimateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 房屋测算
 *
 * @Author Feng
 * @date 2023/5/29
 */
@Tag(name = "管理后台 - 房屋测算")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping(ApiConstants.NAME + "/estimate")
public class EstimateController {

    private final IEstimateService estimateService;

    /**
     * 房屋勘测系数计算
     *
     * @param req
     * @return
     */
    @Operation(summary = "房屋勘测系数计算")
    @PostMapping("/survey-factor")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:estimate:compute')")
    public CommonResult<SurveyResp> surveyFactor(@RequestBody @Valid SurveyReq req) {
        return CommonResult.success(estimateService.surveyFactor(req));
    }

    /**
     * 基准价计算
     *
     * @return
     */
    @Operation(summary = "基准价计算")
    @PostMapping("/basic-price")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:estimate:compute')")
    public CommonResult<BasicPriceResp> basicPrice(@RequestBody @Valid BasicPriceReq req) {
        return CommonResult.success(estimateService.basicPrice(req));
    }

    /**
     * 装修估价计算
     *
     * @param req
     * @return
     */
    @Operation(summary = "装修估价计算")
    @PostMapping("/decoration-evaluate")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:estimate:compute')")
    public CommonResult<DecorationEvaluateResp> decorationEvaluate(@RequestBody @Valid DecorationEvaluateReq req) {
        return CommonResult.success(estimateService.decorationEvaluate(req));
    }

    /**
     * 租金估算
     *
     * @param req
     * @return
     */
    @Operation(summary = "租金估算")
    @PostMapping("/rent-evaluate")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:estimate:compute')")
    public CommonResult<RentEvaluateResp> rentEvaluate(@RequestBody @Valid RentEvaluateReq req) {
        return CommonResult.success(estimateService.rentEvaluate(req));
    }

    /**
     * 计算最高价
     *
     * @param req
     * @return
     */
    @Operation(summary = "计算最高价")
    @PostMapping("/highest-price")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:estimate:compute')")
    public CommonResult<HighestPriceResp> highestPrice(@RequestBody @Valid HighestPriceReq req) {
        return CommonResult.success(estimateService.highestPrice(req));
    }

    /**
     * 勘测保存|修改
     *
     * @param req
     * @return
     */
    @Operation(summary = "勘测保存|修改")
    @PostMapping("/save-update")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:estimate:compute')")
    public CommonResult<Boolean> saveOrUpdate(@RequestBody @Valid EstimateSaveOrUpdateReq req) {
        return CommonResult.success(estimateService.saveOrUpdate(req));
    }

    /**
     * 根据ID获取详情
     *
     * @param id
     * @return
     */
    @Operation(summary = "根据ID获取详情")
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "id")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:estimate:query')")
    public CommonResult<EstimateResp> get(@PathVariable("id") Long id) {
        return CommonResult.success(estimateService.get(id));
    }

    /**
     * 分页查询
     *
     * @param req
     * @return
     */
    @Operation(summary = "分页查询")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:estimate:query')")
    public CommonResult<PageResult<EstimatePageResp>> page(@Valid EstimatePageReq req) {
        return CommonResult.success(estimateService.page(req));
    }


    @Operation(summary = "关联房源")
    @PostMapping("/related-house")
    public CommonResult<Boolean> relatedHouse(@RequestBody @Valid RelatedHouseReq req) {
        return CommonResult.success(estimateService.relatedHouse(req));
    }
}
